﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using D2.PathfinderHub.ViewModel;
using System.Windows.Controls.Primitives;

namespace D2.PathfinderHub.View.Controls
{
    [TemplatePart(Name = "PART_Popup", Type = typeof(Popup))]
    public class DescriptiveComboBox : ComboBox
    {
        private Popup partPopup;

        static DescriptiveComboBox()
        {
            DefaultStyleKeyProperty.OverrideMetadata(typeof(DescriptiveComboBox), new FrameworkPropertyMetadata(typeof(DescriptiveComboBox)));

        }

        public string FieldName
        {
            get { return (string)GetValue(FieldNameProperty); }
            set { SetValue(FieldNameProperty, value); }
        }

        // Using a DependencyProperty as the backing store for FieldName.  This enables animation, styling, binding, etc...
        public static readonly DependencyProperty FieldNameProperty =
            DependencyProperty.Register("FieldName", typeof(string), typeof(DescriptiveComboBox), new UIPropertyMetadata("myComboBox"));

        public string Description
        {
            get { return (string)GetValue(DescriptionProperty); }
            set { SetValue(DescriptionProperty, value); }
        }

        // Using a DependencyProperty as the backing store for Description.  This enables animation, styling, binding, etc...
        public static readonly DependencyProperty DescriptionProperty =
            DependencyProperty.Register("Description", typeof(string), typeof(DescriptiveComboBox), new UIPropertyMetadata("myDescription"));

        protected override void OnPreviewMouseDown(MouseButtonEventArgs e)
        {
            base.OnPreviewMouseDown(e);
            //partPopup.IsOpen = !partPopup.IsOpen;
            IsDropDownOpen = !IsDropDownOpen;
        }

        public override void OnApplyTemplate()
        {
            base.OnApplyTemplate();
            partPopup = GetTemplateChild("PART_Popup") as Popup;
        }
    }
}
